package com.marst.first.controller;

import com.alibaba.fastjson.JSONObject;
import com.marst.first.bean.User;
import com.marst.first.bean.VO.Result;
import com.marst.first.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * @param account
     * @param password
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "login")
    public Result login(@RequestParam("account") String account, @RequestParam("password") String password) {
        log.info("user login start running ... params:account={},password={}", account, password);
        return userService.login(account, password);
    }

    /**
    * @Description: 新增用户
    * @Param: [user]
    * @return: com.marst.first.bean.VO.Result
    * @Author: ZhaoYang
    * @Date: 2024/10/22
    */
    @RequestMapping(method = RequestMethod.POST,value = "addUser")
    public Result addUser(@RequestBody User user) {
        return userService.addUser(user);
    }
    /** 
    * @Description: 查询全部数据
    * @Param: [params]
    * @return: com.marst.first.bean.VO.Result
    * @Author: ZhaoYang
    * @Date: 2024/10/22
    */
    
    @RequestMapping(method = RequestMethod.POST,value = "list")
    public Result list(@RequestBody JSONObject params){
        return userService.list(params);
    }

    /** 
    * @Description: 删除用户(逻辑删除)
    * @Param: [id]
    * @return: com.marst.first.bean.VO.Result
    * @Author: ZhaoYang
    * @Date: 2024/10/22
    */
    
    @RequestMapping(method = RequestMethod.GET,value ="deleteUserOnLogic")
    public Result deleteUserOnLogic(int id) {
        log.info("user delete start running ... params:id={}", id);
        return userService.deleteUserOnLogic(id);
    }
    /** 
    * @Description: 根据id查询详情
    * @Param: [id]
    * @return: com.marst.first.bean.VO.Result
    * @Author: ZhaoYang
    * @Date: 2024/10/22
    */
    
    @RequestMapping(method = RequestMethod.GET,value = "getUserById")
    public Result getUserById(int id) {
        return userService.getUserById(id);
    }

    /** 
    * @Description: 修改用户
    * @Param: [user]
    * @return: com.marst.first.bean.VO.Result
    * @Author: ZhaoYang
    * @Date: 2024/10/22
    */

    @RequestMapping(method = RequestMethod.POST,value = "updateUserById")
    public Result updateUserById(@RequestBody User user) {
        return userService.updateUserById(user);
    }






}
